class Solution {
public:
    unordered_map<int, int> mp;
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) 
    {
        for (int i = 0; i < nums1.size(); i++) {
            if (!mp.count(nums1[i])) {
                mp[nums1[i]] = 1;
            } else {
                mp[nums1[i]]++;
            }
        }
        vector<int>ans;
        for (int i = 0; i < nums2.size(); i++) {
            if (mp.count(nums2[i]) && mp[nums2[i]]) {
                ans.emplace_back(nums2[i]);
                mp[nums2[i]]--;
            }
        }
        return ans;
    }
};
/**
 * @brief 2022.7.19
 * 哈希
 */